package com.wangxu.blog.controller;

import com.wangxu.blog.service.ArticleService;
import com.wangxu.blog.vo.Result;
import com.wangxu.blog.vo.params.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController //json数据进行交互
@RequestMapping("articles")
public class ArticleController {

    @Autowired
    ArticleService articleService;

    /**
     * 首页 文章列表数据
     * @param pageParams 请求过来的参数
     * @return 返回Result类型的响应结果
     */
    @PostMapping
    public Result listArticle(@RequestBody PageParams pageParams){
        return articleService.listArticle(pageParams);
    }

    /**
     * 首页最热文章
     * @return 返回Result数据
     */
    @PostMapping("/hot")
    public Result HotArticle(){
        int limit = 5;
        return articleService.HotArticle(limit);
    }

    /**
     * 首页最新文章
     * @return 返回Result数据
     */
    @PostMapping("/new")
    public Result newArticle(){
        int limit = 3;
        return articleService.newArticle(limit);
    }

    /**
     * 文章归档
     * @return 返回Result对象
     */
    @PostMapping("listArchives")
    public Result listArchives(){
        return articleService.listArticles();
    }

    @PostMapping("/view/{id}") //@PathVariable:获取路径中占位符的数据
    public Result findArticleById(@PathVariable("id") Long articleId){
        return articleService.findArticleById(articleId);
    }
}
